--*********************************************************************
	--*  Close curret writing file
	--*  
	fn closeOutputFile =
	(
		if gFilestream != undefined then
		(
			fflush gFilestream
			fclose gFilestream
			gFilestream = undefined
		)
	)

	--*********************************************************************
	--*  Opens speicifed file for writing
	--*  
	fn openOutputFile filename = 
	(
		if gFilestream != undefined then
			closeOutputFile

		filePath = "C:\\Documents and Settings\\Dacre Denny\\My Documents\\Portfolio\\Tech Demos\\Source\\bin\\" + gProjectName + "content\\models\\" + filename
		gFilestream = fopen filePath "wbc"
	)
	
--*********************************************************************
--*  
fn GetProjectContentDir =
(
	return (("C:\\Documents and Settings\\Dacre Denny\\My Documents\\Portfolio\\Tech Demos\\Source\\bin\\" + gProjectName + "content\\") as string)
)	

--*********************************************************************
--*  
fn WriteVector vec =
(		
		x = (vec[1] as Float)
		y = (vec[2] as Float)
		z = (vec[3] as Float)
		
		if (writefloat gFilestream x) == false then
			print "error"
		if (writefloat gFilestream z) == false then
			print "error"
		if (writefloat gFilestream y) == false then
			print "error"

)

--*********************************************************************
--*  
fn WriteUnmodifiedVector vec =
(		
		x = (vec[1] as Float)
		y = (vec[2] as Float)
		z = (vec[3] as Float)
		
		if (writefloat gFilestream x) == false then
			print "error"
		if (writefloat gFilestream y) == false then
			print "error"
		if (writefloat gFilestream z) == false then
			print "error"

)

--*********************************************************************
--*  
fn WriteFloatSafe val =
(	
	valFloat = (val as Float)
	if (writefloat gFilestream valFloat) == false then
			print "error"
)

--*********************************************************************
--*  
fn WriteMatrix mat =
(	
	
		r1 = normalize ( mat.row1 as Point3)
		r2 = normalize ( mat.row2 as Point3)
		r3 = normalize ( mat.row3 as Point3)
		r4 = ( mat.row4 as Point3)
	 

		WriteFloatSafe (r1[1] as Float)
		WriteFloatSafe (r1[3] as Float)
		WriteFloatSafe (r1[2] as Float)
	
		WriteFloatSafe (r3[1] as Float)
		WriteFloatSafe (r3[3] as Float)
		WriteFloatSafe (r3[2] as Float)
	
		WriteFloatSafe (r2[1] as Float)
		WriteFloatSafe (r2[3] as Float)
		WriteFloatSafe (r2[2] as Float)
	
		WriteFloatSafe r4[1]
		WriteFloatSafe r4[3]
		WriteFloatSafe r4[2]
)

--*********************************************************************
--*  
fn WriteTexCoord vec =
(
		u = (vec[1] as float)
		v = (vec[2] as float)

		if (writefloat gFilestream (u as Float)) == false then
			print "error"
		if (writefloat gFilestream (v as Float)) == false then
			print "error"
)

fn writeFileStr str = 
(
	if str != undefined then
	(
		writestring gFilestream str
	)
	
	writebyte gFilestream 10
)